***** RUN DO_MASTER.do ***** do "$Do_files\DO_MASTER.do"

global program "Main_Figure2"
cap log close
cap log using "$Log_files\log_$program$today", replace

**** REPLICATION OF FIGURE 2 ****

clear all
set mem 2g
set more off

// Import data

use $Data\data_news_voting, clear

// Get controls

global ctrl_base	"sh_lde lpop_A sh_F sh_F_new sh_cspsup sh_sec sh_ter lmean_reink lmean_reink2 charact_altitude charact_altitude_std sh_active sh_young sh_prot sh_M mk com_property" // ptySR_F_N" //  com_property"
global ctrl_plus	"mean_votation lcrSR_F_N"
global fe			"charact_agglo"
global fe_iv		"I_charact_agglo_*"
global cluster		"charact_agglo"

// Generate Sr-LR deviation

cap drop lcrSR_F_N
rename lcrSR_F_N_com lcrSR_F_N
rename lcrLR_F_N_com lcrLR_F_N

g lcrDEV_F_N = lcrSR_F_N - lcrLR_F_N 

// Standardize variables

center lcrLR_F_N lcrSR_F_N lcrDEV_F_N $ctrl_base $ctrl_plus, inplace standardize

// Labels

la var lpop_A 			"Log population"
la var sh_lde 			"German-speaking (%)"
la var sh_prot 			"Protestants (%)"
la var sh_F 			"Immigrants (%)"
la var sh_F_new			"Net Immigration (%)"
la var sh_cspsup		"High-skilled (%)"
la var lmean_reink		"Log Income"
la var sh_sec			"Secondary emp. (%)"
la var sh_ter			"Tertiary emp. (%)"
la var charact_altitude	"Ruggedness"
la var sh_active 		"Active (%)"
la var sh_young 		"Young (%)"
la var mean_votation 	"Past votes outcome"
la var sh_M 			"Muslim (%)"

// First Figure (Short-Run)

foreach var in $ctrl_base $ctrl_plus{
	eststo: reg lcrSR_F_N `var', cluster(charact_agglo) nocons
	estimates store OLS_`var'_SR
}

global OLS_estimates_SR "OLS_lpop_A_SR \ OLS_sh_lde_SR \ OLS_sh_prot_SR \ OLS_sh_F_SR \ OLS_sh_F_new_SR \  OLS_sh_cspsup_SR \ OLS_lmean_reink_SR \ OLS_sh_M_SR \ OLS_charact_altitude_SR \ OLS_sh_active_SR \ OLS_sh_young_SR \ OLS_mean_votation_SR"

coefplot ($OLS_estimates_SR), drop(_cons) xlabel(-0.1(0.05)0.1, labsize(small)) ylabel(, angle(0) labsize(vsmall)) ///
	horizontal fcolor(*.5) ciopts(recast(rcap) color(black)) citop format(%9.2f) ///
	levels(95) xline(0, lpattern(dash) lcolor(gs12)) xtitle("", margin(small)) ///
	mlabel mlabposition(12) mlabcolor(black) mlabgap(*2) mcolor(black) ///
	legend(lab(1 "Estimated coefficients") lab(2 "CI (90%)") order(1 2) region(color(white)) symxsize(*0.5) size(vsmall)) bgcolor(white) graphregion(color(white))

// Second Figure (Long-Run)

foreach var in $ctrl_base $ctrl_plus{
	eststo: reg lcrLR_F_N `var', cluster(charact_agglo) nocons
	estimates store OLS_`var'_LR
}

global OLS_estimates_LR "OLS_lpop_A_LR \ OLS_sh_lde_LR \ OLS_sh_prot_LR \ OLS_sh_F_LR \ OLS_sh_F_new_LR \  OLS_sh_cspsup_LR \ OLS_lmean_reink_LR \ OLS_sh_M_LR \ OLS_charact_altitude_LR \ OLS_sh_active_LR \ OLS_sh_young_LR \ OLS_mean_votation_LR"

coefplot ($OLS_estimates_LR), drop(_cons) xlabel(-0.1(0.05)0.1, labsize(small)) ylabel(, angle(0) labsize(vsmall)) ///
	horizontal fcolor(*.5) ciopts(recast(rcap) color(black)) citop format(%9.2f) ///
	levels(95) xline(0, lpattern(dash) lcolor(gs12)) xtitle("", margin(small)) ///
	mlabel mlabposition(12) mlabcolor(black) mlabgap(*2) mcolor(black) ///
	legend(lab(1 "Estimated coefficients") lab(2 "CI (90%)") order(1 2) region(color(white)) symxsize(*0.5) size(vsmall)) bgcolor(white) graphregion(color(white))

// Third Figure (Deviation)

foreach var in $ctrl_base $ctrl_plus{
	eststo: reg lcrDEV_F_N `var', cluster(charact_agglo) nocons
	estimates store OLS_`var'_DV
}

global OLS_estimates_DV "OLS_lpop_A_DV \ OLS_sh_lde_DV \ OLS_sh_prot_DV \ OLS_sh_F_DV \ OLS_sh_F_new_DV \  OLS_sh_cspsup_DV \ OLS_lmean_reink_DV \ OLS_sh_M_DV \ OLS_charact_altitude_DV \ OLS_sh_active_DV \ OLS_sh_young_DV \ OLS_mean_votation_DV"

coefplot ($OLS_estimates_DV), drop(_cons) xlabel(-0.1(0.05)0.1, labsize(small)) ylabel(, angle(0) labsize(vsmall)) ///
	horizontal fcolor(*.5) ciopts(recast(rcap) color(black)) citop format(%9.2f) ///
	levels(95) xline(0, lpattern(dash) lcolor(gs12)) xtitle("", margin(small)) ///
	mlabel mlabposition(12) mlabcolor(black) mlabgap(*2) mcolor(black) ///
	legend(lab(1 "Estimated coefficients") lab(2 "CI (90%)") order(1 2) region(color(white)) symxsize(*0.5) size(vsmall)) bgcolor(white) graphregion(color(white))

// Combined graph

coefplot ($OLS_estimates_SR), bylabel(Short-Run) ///
	|| ($OLS_estimates_LR), bylabel(Long-Run)  ///
	|| ($OLS_estimates_DV), bylabel(Deviation)  ///
	||, xlabel(-0.1 "-0.10" 0 "0" 0.1 "0.10", labsize(small) format(%9.2f)) xscale(r(-0.11(0.11)0.11)) ylabel(, angle(0) labsize(vsmall)) ///
	horizontal fcolor(*.5) ciopts(recast(rcap) color(black)) citop format(%9.2f) ///
	levels(90) xline(0, lpattern(dash) lcolor(gs12)) xtitle("", margin(small)) ///
	subtitle(, size(small) bmargin(top) margin(vsmall) color(white) bcolor(black)) ///
	msize(small) mlabel mlabposition(12) mlabcolor(black) mlabgap(*1) mlabsize(tiny) mcolor(black) ///
	byopts(cols(3) legend(off) bgcolor(color(white)) graphregion(color(white)))
graph export 	"$Results\\$program.pdf", as(pdf) replace

cap log close
